package com.atguigu.java8.lambdaDemo;

import org.junit.Test;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * @author Xiaohong X Gou
 * @createTime 2022-10-11 14:01
 * @description
 */
public class TestLambda3 {
    List<Employee> emps = Arrays.asList(
            new Employee(1,"张三",18,9999.99),
            new Employee(2,"李四",38,5555.99),
            new Employee(3,"王五",50,6666.66),
            new Employee(4,"赵六",16,3333.33),
            new Employee(5,"田七",8,7777.77)
    );
    @Test
    public void test1(){
        Collections.sort(emps,(e1,e2)->{
            if (e1.getAge() ==e2.getAge()){
                return e1.getName().compareTo(e2.getName());
            }else {
                return -Integer.compare(e1.getAge(),e2.getAge());
            }
        });
        for (Employee emp :
                emps) {
            System.out.println(emp);
        }
    }

    @Test
    public void test2(){
        String trimStr = strHandler("\t\t\t 盛大互动我  ", (str) -> str.trim());
        System.out.println(trimStr);
        String upper = strHandler("abcdef", str -> str.toUpperCase());
        System.out.println(upper);

        String Index = strHandler("所管辖区域的商品", str -> str.substring(1, 5));
        System.out.println(Index);

    }
    public String strHandler(String str,MyFunction mf){
        return mf.getValue(str);
    }
    @Test
    public void test3(){
        op(100L,200L,(x,y)->x+y);
        op(100L,200L,(x,y)->x*y);
    }
    public void op(Long l1, Long l2,MyFunction2<Long,Long> mf){
        System.out.println(mf.getValue(l1,l2));
    }
}
